<?php
require_once 'jsonOut.func.php';
$uname = $_POST["username"];
$psw = $_POST["pswrod"];

if (!isset($uname) || !isset($psw)) {
	jsonOut(201, '用户名或密码为空了', array());
	die();
}

// if (strlen($psw) < 6) {
// 	jsonOut(201, '密码长度不足', array());
// 	die();
// }

$sql = new mysqli("localhost", "lnf", "", "lostnfound");
if ($sql->connect_error) {
	jsonOut(3306, '数据库出错'.$sql->connect_error, array());
	die();
}

$res = $sql->query("select paswrod from user where uname='$uname' or phone='$uname' or email='$uname'");
if ($res) {
	$row = $res->fetch_array(MYSQLI_ASSOC);
	if (!$row) {
		jsonOut(201, '用户未注册', array());
		die();
	}
	$passwdr = $row["paswrod"];
	if (!$passwdr) {
		jsonOut(201, '用户未完成注册', array());
		die();
	}
	$pdres = $sql->query("select PASSWORD('$psw')");
	$pdrow = $pdres->fetch_array()[0];

	if ($pdrow != $passwdr) {
		jsonOut(201, '用户名或密码不正确', array());
		die();
	}

	jsonOut(200, '用户登录成功', array());

}